from flask_sqlalchemy import SQLAlchemy

db = SQLAlchemy()


#  供应商
class Vendor(db.Model):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True, comment='供应商ID')
    name = db.Column(db.String(64), comment='供应商名称')
    linkman = db.Column(db.String(16), comment='联系人')
    mobile = db.Column(db.String(11), comment='联系电话')
    remark = db.Column(db.String(64), comment='备注')


#  商品
class Good(db.Model):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True, comment='商品ID')
    name = db.Column(db.String(64), comment='商品名称')
    code = db.Column(db.String(16), comment='商品编码')
    pec = db.Column(db.String(16), comment='商品规格')
    retailPrice = db.Column(db.Float, comment='零售价')
    purchasePrice = db.Column(db.Float, comment='进货价')
    storageNum = db.Column(db.Integer, comment='库存数量')
    supplierId = db.Column(db.Integer, comment='供应商ID')
    supplierName = db.Column(db.String(16), comment='供应商名字')

#  员工
class Worker(db.Model):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True, comment='员工ID')
    username = db.Column(db.String(64), comment='账号')
    name = db.Column(db.String(16), comment='名字')
    age = db.Column(db.Integer, comment='年龄')
    mobile = db.Column(db.String(11), comment='联系电话')
    salary = db.Column(db.Float(2, 6), comment='薪资')
    entryDate = db.Column(db.Date, comment='入职时间')
    quit = db.Column(db.BOOLEAN, comment='离职状态')

    def to_dict(self):
        return {
            "id": self.id,
            "username": self.username,
            "name": self.name,
            "age": self.age,
            "mobile": self.mobile,
            "salary": float(self.salary),
            "entryDate": str(self.entryDate),
        }


#  会员
class Vip(db.Model):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True, comment='会员ID')
    cardNum = db.Column(db.String(64), comment='vip卡号')
    name = db.Column(db.String(16), comment='名字')
    integral = db.Column(db.Integer, comment='积分')
    phone = db.Column(db.String(11), comment='联系电话')
    money = db.Column(db.Float, comment='开卡金额')
    payType = db.Column(db.Integer, comment='支付类型(0 现金, 1 微信，2 支付宝, 3 银行卡)')
    address = db.Column(db.String(64), comment='地址')
    birthday = db.Column(db.Date, default='', comment='生日')


# 用户
class User(db.Model):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True, comment='用户ID')
    name = db.Column(db.String(64), comment='用户名')
    username = db.Column(db.String(64), comment='账号')
    password = db.Column(db.String(64), comment='密码')
    status = db.Column(db.Boolean, default=1, comment='是否为管理员')
